package com.gopay.common.util.cloud;

import com.gopay.common.util.PatternCheck;
import org.apache.commons.lang3.StringUtils;

/**
 * Created by liuyong on 2017/11/9.
 */
public class CloudPatternCheckUtil {

    public static boolean checkDateDefault(String dateTime) {
        return PatternCheck.validateFormat(dateTime.substring(0, 8), PatternCheck.IS_VALID_DATE_ONLY_NUMBER)
                && PatternCheck.validateFormat(dateTime.substring(8), PatternCheck.IS_TIME);
    }


    public static boolean checkLength(int min, int max, String value) {
        if (!validatorMin(min, value)) {
            return false;
        }
        if (!validatorMax(max, value)) {
            return false;
        }
        return true;
    }

    public static boolean validatorMin(int min, String value) {
        if (StringUtils.isBlank(value)) {
            return true;
        }
        if (value.length() < min) {
            return false;
        }
        return true;
    }

    public static boolean validatorMax(int max, String value) {
        if (StringUtils.isBlank(value)) {
            return true;
        }
        if (value.length() > max) {
            return false;
        }
        return true;
    }
}
